//
//  GroupSwapFaceViewController.m
//  cam
//
//  Created by VIETHUNG on 1/2/14.
//  Copyright (c) 2014 DanielLe. All rights reserved.
//

#import "GroupSwapFaceViewController.h"
#import "DetailSwapFaceViewController.h"
#import "DataSingleton.h"
#import "AmobiSDK.h"

#define ITEM_SPACING 200

@interface GroupSwapFaceViewController ()

@end

@implementation GroupSwapFaceViewController
@synthesize arrayImage;
@synthesize carousel;

-(id)init{
    self = [super init];
    if (IS_IOS7) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = YES;
    }
    
    return self;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.view addSubview:[AmobiSDK ShowAmobiSDK:CGPointMake(160, 100) :1]];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;    
	DataSingleton *data = [DataSingleton shareManager];
    arrayImage = [data arrayItem:0];
    
    carousel.delegate = self;
    carousel.dataSource = self;
    carousel.type = iCarouselTypeCoverFlow;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.carousel = nil;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    
}

- (IBAction)act_back:(id)sender {
    self.carousel.hidden = YES;
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)act_info:(id)sender {
    
}

#pragma mark -

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return 10;
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
    UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"h%d.jpg",index]]];
    
    view.frame = CGRectMake(70, 80, 180, 260);
    return view;
}

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
	return 0;
}

- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
    return 10;
}

- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
    return ITEM_SPACING;
}

- (CATransform3D)carousel:(iCarousel *)_carousel transformForItemView:(UIView *)view withOffset:(CGFloat)offset
{
    view.alpha = 1.0 - fminf(fmaxf(offset, 0.0), 1.0);
    
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = self.carousel.perspective;
    transform = CATransform3DRotate(transform, M_PI / 8.0, 0, 1.0, 0);
    return CATransform3DTranslate(transform, 0.0, 0.0, offset * carousel.itemWidth);
}

- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
    return true;
}

//select item at index
-( void) selectItemAtIndex:(NSInteger)index
{
    NSLog(@"=======%d",index);
    UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailSwapFaceViewController"];
    [vc setModalPresentationStyle:UIModalPresentationCustom];
    [self presentModalViewController:vc animated:YES];
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

@end
